define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'goods/index' + location.search,
                  //  add_url: 'goods/add',
                   // edit_url: 'goods/edit',
                    //del_url: 'goods/del',
                    multi_url: 'goods/multi',
                    import_url: 'goods/import',
                    table: 'goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                       // {field: 'category_id', title: __('Category_id')},
                        {field: 'goods_no', title: __('Goods_no'), operate: 'LIKE'},
                        {field: 'person_max', title: __('Person_max')},
                        {field: 'person_real', title: __('Person_real')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'departtime', title: __('Departtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'uptotime', title: __('Uptotime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        // {field: 'createtime', title: __('Createtime')},
                        // {field: 'updatetime', title: __('Updatetime')},
                        // {field: 'office_id', title: __('Office_id')},
                        // {field: 'shop_id', title: __('Shop_id')},
                        // {field: 'store_id', title: __('Store_id')},
                        {field: 'switch', title: __('Switch'), searchList: {"1":__('Switch 1'),"0":__('Switch 0')}, table: table, formatter: Table.api.formatter.toggle},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'status', title: __('Status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        {field: 'goodscategory.name', title: __('Goodscategory.name'), operate: 'LIKE'},
                        {field: 'branchofficeoffice.name', title: __('Branchofficeoffice.name'), operate: 'LIKE'},
                        {field: 'manystoreshop.name', title: __('Manystoreshop.name'), operate: 'LIKE'},
                        {field: 'manystore.username', title: __('Manystore.username'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});